package com.fubang.rxjavalearning;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import rx.Observable;
import rx.Subscriber;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //基本创建用法
        Observable.create(new Observable.OnSubscribe<Integer>() {
            @Override
            public void call(Subscriber<? super Integer> subscriber) {
                for (int i = 0; i < 5; i++) {
                    subscriber.onNext(i);
                }
                subscriber.onCompleted();
            }
        }).subscribe(new Subscriber<Integer>() {
            @Override
            public void onCompleted() {
                System.out.println("complete0");
            }

            @Override
            public void onError(Throwable e) {
                System.out.println("error0");
            }

            @Override
            public void onNext(Integer integer) {
                System.out.println("第一种" + integer);
            }
        });
        //just创建方法
        Observable<String> observable = Observable.just("a", "b", "c", "d");
        observable.subscribe(new Subscriber<String>() {
            @Override
            public void onCompleted() {
                System.out.println("complete1");
            }

            @Override
            public void onError(Throwable e) {
                System.out.println("error1");
            }

            @Override
            public void onNext(String o) {
                System.out.println("第二种" + o);

            }
        });
    }
}
